package com.habdqn.dubbo.spring.boot.demo.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.habdqn.dubbo.spring.boot.demo.entity.Detail;
import com.habdqn.dubbo.spring.boot.demo.service.DetailService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 帖子明细表(Detail)表控制层
 *
 * @author xing.jiejian
 * @since 2019-04-10 14:56:11
 */
@RestController
@RequestMapping("/detail")
public class DetailController {
    /**
     * 服务对象
     */
    @Reference(version = "${demo.service.version}",url = "${demo.service.url}")
    private DetailService detailService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    public Detail selectOne(@PathVariable("id") Integer id) {
        return this.detailService.queryById(id);
    }


    @PostMapping("/page")
    public IPage<Detail> listBySortId(@RequestParam(defaultValue = "1",name = "pageNo") int pageNo,@RequestParam("sortId") int sortId){
        IPage<Detail> details = detailService.findPageBySortId(pageNo,5,sortId);
        return details;
    }
}